export function minus(a, b) {
  if (typeof a === 'string') {
    if (a > b) {
      return 1
    } else if (a < b) {
      return -1
    } else {
      return 0
    }
  } else if (typeof a === 'number') {
    return a - b
  } else {
    return 0
  }
}

export function processQuestion(item) {
  return {
    ...item,
    question_form: item.question_form === 1 ? '选择' : '填空',
    question_type: item.question_type
  }
}

export function processTypes(list) {
  function find(id) {
    return list.find(item => item.id === id)
  }
  function getName(item) {
    if (item.parent_id !== 0) {
      return getName(find(item.parent_id)) + '/' + item.type_name
    } else {
      return item.type_name
    }
  }
  return list.map(item => {
    return {
      id: item.id,
      name: getName(item)
    }
  }).sort((a, b) => minus(a.name, b.name))
}
